<template>
	<view class="page">
		<view class="list">
			<view class="listX">
				<view class="title">1V1价格</view>
				<view class="bottom">
					<view class="input" >
						<view class="disabled" v-if="price_type_a == 0" @tap="setPrice(0)">该类型价格无法设置</view>
						<u-input height="72" placeholder-style="color:#bfbfbf;" v-else  v-model="value1" placeholder="请输入金额~" maxlength="8" type="number"  />
					</view>
					
					<view class="explain">元/场次</view>
				</view>
			</view>
			<view class="listX">
				<view class="title">1V2价格</view>
				<view class="bottom" >
					<view class="input" @tap="setPrice(1)">
						<view class="disabled" v-if="price_type_b == 0">该类型价格无法设置</view>
						<u-input height="72" placeholder-style="color:#bfbfbf;" v-else v-model="value2" placeholder="请输入金额~" maxlength="8" type="number"  />
					</view>
					<view class="explain">元/场次</view>
				</view>
			</view>
			<view class="listX">
				<view class="title">1V3/4价格</view>
				<view class="bottom" >
					<view class="input"  @tap="setPrice(2)">
						<view class="disabled" v-if="price_type_c == 0">该类型价格无法设置</view>
						<u-input height="72"  placeholder-style="color:#bfbfbf;" v-else v-model="value3" placeholder="请输入金额~" maxlength="8" type="number"  />
					</view>
					<view class="explain">元/场次</view>
				</view>
			</view>
			<view class="listX">
				<view class="title">高球助理</view>
				<view class="bottom" >
					<view class="input" @tap="setPrice(3)">
						<view class="disabled" v-if="price_type_d == 0">该类型价格无法设置</view>
						<u-input height="72" placeholder-style="color:#bfbfbf;" v-else v-model="value4" placeholder="请输入金额~" maxlength="8" type="number"  />
					</view>
					<view class="explain">元/场次</view>
				</view>
			</view>
			<view class="listX">
				<view class="title">巡回赛球童</view>
				<view class="bottom" >
					<view class="input" @tap="setPrice(4)">
						<view class="disabled" v-if="price_type_e == 0">该类型价格无法设置</view>
						<u-input height="72" placeholder-style="color:#bfbfbf;" v-else v-model="value5" placeholder="请输入金额~" maxlength="8" type="number"  />
					</view>
					<view class="explain">元/场次</view>
				</view>
			</view>
		</view>
		<view class="tx_btn" @tap="priceInfo">
			保存
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				value1: '',
				value2: '',
				value3: '',
				value4: '',
				value5: '',
				price_type_a: '',
				price_type_b: '',
				price_type_c: '',
				price_type_d: '',
				price_type_e: '',
			}
		},
		methods: {
			
			priceInfo() {
				// if(this.value1 == '' && this.value2 == '' && this.value3 == '' && this.value4 == '') {
				// 	this.$message.info('请输入金额')
					
				// }
				if (this.price_type_a == 1) {
					if (this.value1 == '') {
						this.$message.info('请输入正确金额')
						return false
					} else {
						if(!this.isNumber(this.value1)) {
							this.$message.info('请输入正确金额')
							return false
						}
					}
				}
				if (this.price_type_b == 1) {
					if (this.value2 == '') {
						this.$message.info('请输入正确金额')
						return false
					} else {
						if(!this.isNumber(this.value2)) {
							this.$message.info('请输入正确金额')
							return false
						}
					}
				}
				if (this.price_type_c == 1) {
					if (this.value3 == '') {
						this.$message.info('请输入正确金额')
						return false
					} else {
						if(!this.isNumber(this.value3)) {
							this.$message.info('请输入正确金额')
							return false
						}
					}
				}
				if (this.price_type_d == 1) {
					if (this.value4 == '') {
						this.$message.info('请输入正确金额')
						return false
					} else {
						if(!this.isNumber(this.value4)) {
							this.$message.info('请输入正确金额')
							return false
						}
					}
				}
				if (this.price_type_e == 1) {
					if (this.value5 == '') {
						this.$message.info('请输入正确金额')
						return false
					} else {
						if(!this.isNumber(this.value5)) {
							this.$message.info('请输入正确金额')
							return false
						}
					}
				}
				let x1 = this.value1.toString().indexOf('.') + 1;   //小数点的位置
				if (x1 != 0) {
					var y1 = this.value1.toString().length - x1;  //小数的位数
					if(y1 > 2){
					    this.$message.info('请输入正确金额')
						return false
					}
				}
				
				let x2 = this.value2.toString().indexOf('.') + 1;   //小数点的位置
				if (x2 != 0) {
					var y2 = this.value2.toString().length - x2;  //小数的位数
					if(y2 > 2){
					    this.$message.info('请输入正确金额')
						return false
					}
				}
				let x3 = this.value3.toString().indexOf('.') + 1;   //小数点的位置
				if (x3 != 0) {
					var y3 = this.value3.toString().length - x3;  //小数的位数
					if(y3 > 2){
					    this.$message.info('请输入正确金额')
						return false
					}
				}
				let x4 = this.value4.toString().indexOf('.') + 1;   //小数点的位置
				if (x4 != 0) {
					var y4 = this.value4.toString().length - x4;  //小数的位数
					if(y4 > 2){
					    this.$message.info('请输入正确金额')
						return false
					}
				}
				let x5 = this.value5.toString().indexOf('.') + 1;   //小数点的位置
				if (x5 != 0) {
					var y5 = this.value5.toString().length - x5;  //小数的位数
					if(y5 > 2){
					    this.$message.info('请输入正确金额')
						return false
					}
				}
				this.$api.post(global.apiUrls.positioningInfo, {
					price_a: this.value1,
					price_b: this.value2,
					price_c: this.value3,
					price_d: this.value4,
					price_e: this.value5
				}).then(res => {
					this.$message.info(res.data.msg)
					if(res.data.code == 1) {
						setTimeout(() => {
							uni.navigateBack({
								delta: 1
							})
						}, 800)
					} else {
						
					}
				})
			},
			// 获取定价信息
			priceInfotow() {
				this.$api.post(global.apiUrls.priceMessage, {
					
				}).then(res => {
					uni.hideLoading()
					// console.log(res)
					this.value1 = res.data.data.price_a
					this.value2 = res.data.data.price_b
					this.value3 = res.data.data.price_c
					this.value4 = res.data.data.price_d
					this.value5 = res.data.data.price_e
					var arr = res.data.data.type
					for(var i in arr){
						if(arr[i]==1){
							this.price_type_a = 1
						}else if(arr[i]==2){
							this.price_type_b = 1
						}else if(arr[i]==3){
							this.price_type_c = 1
						}else if(arr[i]==4){
							this.price_type_d = 1
						}else if(arr[i]==5){
							this.price_type_e = 1
						}
					}
				})
			},
			// 设置提示
			setPrice(k) {
				// console.log(k)
				// if (this.type[k] == undefined) {
					
				// }
				this.$message.info('该类型价格无法设置')
			},
			// 判断是否为数字
			isNumber(val){
				if(!isNaN(val)){
				        return true;
				    }else{
				        return false;
				    }
			}
		},
		onLoad() {},
		onShow() {
			uni.showLoading({
				title: '加载中'
			})
			this.priceInfotow()
		},
		onPullDownRefresh() {
		  
		},
		onReachBottom() {
		  
		}
	}
</script>

<style lang="scss" scoped>
  .page{
    min-height: 100vh;
    background-color: #FFFFFF;
	color: #333333;
	padding-bottom: 120rpx;
	.list {
		padding: 0 32rpx;
		.listX {
			padding: 32rpx 0;
			border-bottom: 1rpx solid #f2f2f1;
			.title {
				font-size: 32rpx;
				margin-bottom: 24rpx;
			}
			.bottom {
				height: 72rpx;
				display: flex;
				.input {
					background: #f2f2f1;
					width: 100%;
					/deep/.u-input__right-icon {
						line-height: 72rpx;
					}
					// /deep/.uni-input-input {
					// 	color: #BFBFBF;
					// 	padding: 0 24rpx;
					// }
					/deep/.u-input {
						padding: 0 24rpx !important;
						color: #BFBFBF !important;
					}
					.disabled {
						height: 72rpx;
						line-height: 72rpx;
						padding-left: 24rpx;
					}
				}
				.explain {
					width: 135rpx;
					margin-left: 20rpx;
					line-height: 72rpx;
					font-size: 30rpx;
				}
			}
			
		}
	}
	.tx_btn {
		font-size: 32upx;
		color: white;
		line-height: 88upx;
		text-align: center;
		position: fixed;
		bottom: 40upx;
		left: 32upx;
		width: 686rpx;
		height: 88rpx;
		background: #006747;
		opacity: 1;
		border-radius: 8rpx;
	}
  }
  
</style>
